
package com.joysuch.wwyt.audit.service;

import java.util.ArrayList;
import java.util.List;

public class AuditLogContextHolder {

    private static ThreadLocal<List<Object>> holder = new ThreadLocal<>();
    private static ThreadLocal<Boolean> stateHolder = new ThreadLocal<>();

    public static void set(Object obj) {
        List<Object> list = holder.get();
        if (list == null) {
            list = new ArrayList<>(3);
            holder.set(list);
        }
        list.add(obj);
    }

    public static List<Object> get() {
        return holder.get();
    }

    public static void remove() {
        holder.remove();
        stateHolder.remove();
    }

    public static void setState(Boolean state) {
        stateHolder.set(state);
    }

    public static boolean isSuccess() {
        Boolean b = stateHolder.get();
        return b != null && b;
    }
}
